class Solution:
    def findMaxValueOfEquation(self, points: List[List[int]], k: int) -> int:
        q = deque([points[0]])
        ans = -inf
        for x, y in points[1:]:
            while q and x - q[0][0] > k:
                q.popleft()
            if q:
                ans = max(ans, x + y + q[0][1] - q[0][0])
            while q and y - x > q[-1][1] - q[-1][0]:
                q.pop()
            q.append([x, y])
        return ans
